To use email in your server you must have a MTA (Mail Transfer Agent) which assign to routes and transmits electronic mail from one node on a network to another use SMTP (Simple Mail Transfer Protocol). MTA on linux server such as Sendmail, Postfix, Exim, Qmail, Mutt, Alpin, etc.

### PREREQUISITES ###
- Fully qualified domain name (FQDN)
- A valid username and password for the SMTP mail provider, such as Mandrill, SendGrid, or Gmail (If use external SMTP server)
- Make sure the sasl and mail package is installed and up to date:
  >> sudo yum install cyrus-sasl-plain mailx

### HOW TO INSTALLL POSTFIX ###
1. run
   >> sudo yum install postfix

2. Edit file /etc/postfix/main.cf
   >> sudo nano /etc/postfix/main.cf
	## Set your mail server FQDN ##
	myhostname = fqdn.domain.com

	## Set domain name ##
	mydomain = domain.com
	myorigin = $mydomain

	## Set ipv4 ##
	inet_interfaces = all (If use external SMTP server)
	inet_interfaces = loopback-only (If use internal server)

	## Change to all ##
	inet_protocols = all

	## Comment ##
	#mydestination = $myhostname, localhost.$mydomain, localhost,

	## Uncomment ##
	mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

	## Add IP range ##
	mynetworks = 127.0.0.0/8

	## Uncomment ##
	home_mailbox = Maildir/

### CONFIGURE SMTP ### (If use external SMTP server)
1. Open or create the /etc/postfix/sasl/sasl_passwd
   >> sudo nano /etc/postfix/sasl/sasl_passwd
2. Add your destination (SMTP Host), username, and password in the following format:
   [mail.isp.example] username:password
   You can specify a TCP port (such as 587), then use the following format:
   [mail.isp.example]:587 username:password
3. Create the hash db file for Postfix
   >> sudo postmap /etc/postfix/sasl/sasl_passwd
If all went well, you should have a new file named sasl_passwd.db in the /etc/postfix/sasl directory.

### Configure the relay server ### (If use external SMTP server)
1. Edit file /etc/postfix/main.cf
   >> sudo nano /etc/postfix/main.cf
2. Configure "relayhost" parameter. You must use same SMTP host on sasl_password
   # specify SMTP relay host 
   relayhost = [mail.isp.example]:587
3. At the end of the file, add the following parameters to enable authentication:
   # enable SASL authentication 
   smtp_sasl_auth_enable = yes
   # disallow methods that allow anonymous authentication. 
   smtp_sasl_security_options = noanonymous
   # where to find sasl_passwd
   smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
   # Enable STARTTLS encryption 
   smtp_use_tls = yes
   # where to find CA certificates
   smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt

### Restart Postfix ###
 >> sudo systemctl restart postfix or sudo service postfix restart

### TESTING POSTFIX ###
You can test with "mail" command:
>> echo "body of your email" | mail -s "This is a Subject" recipient@elsewhere.com